{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from machine_lib import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'{\"user\":{\"id\":\"JW80368\"},\"token\":{\"expiry\":14400.0},\"permissions\":[\"CONSULTANT\",\"MULTI_SIMULATION\",\"PROD_ALPHAS\",\"REFERRAL\",\"VISUALIZATION\",\"WORKDAY\"]}'\n"
     ]
    }
   ],
   "source": [
    "s = login()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha_id_list = [\n",
    "    \"l3Y2EZe\",\n",
    "    \"OxjmP5b\",\n",
    "    \"aE8Pz06\",\n",
    "    \"3eOnLl6\",\n",
    "    \"Q9A5XGr\",\n",
    "    \"q6pmqzV\",\n",
    "    \"1zRnEVR\",\n",
    "    \"bdgWE2p\",\n",
    "    \"pKkzeAo\",\n",
    "    \"Q9Alpkg\",\n",
    "    \"8eZ6ZYm\",\n",
    "    \"zREJemd\",\n",
    "    \"8eZK17m\",\n",
    "    \"3eOadze\",\n",
    "    \"MLn8NGM\",\n",
    "    \"EeMrJ6P\",\n",
    "    \"5k1618n\",\n",
    "    \"n8lz5Z3\",\n",
    "    \"WVRW8aO\",\n",
    "    \"Q9A5Xqp\",\n",
    "    \"NRGnnXq\",\n",
    "    \"A75OKLE\",\n",
    "    \"JvkXbEE\",\n",
    "    \"vvb5JMb\",\n",
    "    \"R1okWX1\",\n",
    "    \"q6pzJnV\",\n",
    "    \"dR67PMX\",\n",
    "    \"kZMmr9L\",\n",
    "    \"l3YR1Mx\",\n",
    "    \"V3LYJ2G\",\n",
    "    \"n8lOrKx\",\n",
    "    \"X8xYM15\",\n",
    "    \"0MLQ2vq\",\n",
    "    \"YgOW33J\",\n",
    "    \"l3YR10O\",\n",
    "    \"ogX9OGn\",\n",
    "    \"A75OK0Y\",\n",
    "    \"R1oa7p0\",\n",
    "    \"aE8NQax\",\n",
    "    \"97363M2\",\n",
    "    \"bdgPvwr\",\n",
    "    \"1zRn0XK\",\n",
    "    \"exPqRdN\",\n",
    "    \"wEvk77l\",\n",
    "    \"5k2dRzX\",\n",
    "    \"2NxalPZ\",\n",
    "    \"bdgopor\",\n",
    "    \"q6pzwQZ\",\n",
    "    \"aEg9JVx\",\n",
    "    \"KE22XMp\",\n",
    "    \"Q9opRAw\",\n",
    "    \"OxjbKzR\",\n",
    "    \"rPnaLva\",\n",
    "    \"pKpbEAX\",\n",
    "    \"2N2opqZ\",\n",
    "    \"Oxj5xeJ\",\n",
    "    \"Ee2nrLR\",\n",
    "    \"dRPJmwY\",\n",
    "    \"R1vwxKa\",\n",
    "    \"pKpkeov\",\n",
    "    \"X8OOm08\",\n",
    "    \"1zRavoJ\",\n",
    "    \"xdom5mq\",\n",
    "    \"dR6lZZE\",\n",
    "    \"KEp8kMl\",\n",
    "    \"ogk0ww2\",\n",
    "    \"6e2LgEP\",\n",
    "    \"MLn5LRL\",\n",
    "    \"q6pmq5O\",\n",
    "    \"Ge75Ggo\",\n",
    "    \"9723Owe\",\n",
    "    \"A75ne1R\",\n",
    "    \"rPnMa89\",\n",
    "    \"A728XEw\",\n",
    "    \"zRLnard\",\n",
    "    \"rPnMkd1\",\n",
    "    \"exWPZOg\",\n",
    "    \"bdKg1lN\",\n",
    "    \"xdoPjVm\",\n",
    "    \"V3RbQR5\",\n",
    "    \"n8X5NPM\",\n",
    "    \"Yg9owwJ\",\n",
    "    \"Ge7NdOo\",\n",
    "    \"mVNq0m9\",\n",
    "    \"1zRon5k\",\n",
    "    \"EeMgAmm\",\n",
    "    \"l3YR1QN\",\n",
    "    \"Q9oxPXw\",\n",
    "    \"5k2dPZM\"\n",
    "  ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_simulation_result_json(s, alpha_id):\n",
    "    return s.get('https://api.worldquantbrain.com/alphas/' + alpha_id).json()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "for alpha_id in alpha_id_list:\n",
    "    result = get_simulation_result_json(s, alpha_id)\n",
    "    is_perf = result[\"is\"]\n",
    "    pyramids = is_perf[\"pyramids\"]\n",
    "    fitness = is_perf[\"fitness\"]\n",
    "    sharpe = is_perf[\"sharpe\"]\n",
    "    turnover = is_perf[\"turnover\"]*100\n",
    "    margin = is_perf[\"margin\"]*100\n",
    "    drawdown = is_perf[\"drawdown\"]*100\n",
    "    returns = is_perf[\"returns\"]*100\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'pnl': 10444183,\n",
       " 'bookSize': 20000000,\n",
       " 'longCount': 246,\n",
       " 'shortCount': 236,\n",
       " 'turnover': 0.2314,\n",
       " 'returns': 0.1009,\n",
       " 'drawdown': 0.0486,\n",
       " 'margin': 0.000872,\n",
       " 'fitness': 1.41,\n",
       " 'sharpe': 2.14,\n",
       " 'startDate': '2012-07-15',\n",
       " 'checks': [{'name': 'LOW_SHARPE',\n",
       "   'result': 'PASS',\n",
       "   'limit': 1.58,\n",
       "   'value': 2.14},\n",
       "  {'name': 'LOW_FITNESS', 'result': 'PASS', 'limit': 1.0, 'value': 1.41},\n",
       "  {'name': 'LOW_TURNOVER', 'result': 'PASS', 'limit': 0.01, 'value': 0.2314},\n",
       "  {'name': 'HIGH_TURNOVER', 'result': 'PASS', 'limit': 0.7, 'value': 0.2314},\n",
       "  {'name': 'CONCENTRATED_WEIGHT', 'result': 'PASS'},\n",
       "  {'name': 'LOW_SUB_UNIVERSE_SHARPE',\n",
       "   'result': 'PASS',\n",
       "   'limit': 1.23,\n",
       "   'value': 1.65},\n",
       "  {'name': 'SELF_CORRELATION', 'result': 'PENDING'},\n",
       "  {'name': 'DATA_DIVERSITY', 'result': 'PENDING'},\n",
       "  {'name': 'PROD_CORRELATION', 'result': 'PENDING'},\n",
       "  {'name': 'REGULAR_SUBMISSION', 'result': 'PENDING'},\n",
       "  {'name': 'IS_LADDER_SHARPE',\n",
       "   'result': 'PASS',\n",
       "   'year': 7,\n",
       "   'startDate': '2022-07-15',\n",
       "   'endDate': '2015-07-16',\n",
       "   'limit': 1.75,\n",
       "   'value': 1.85},\n",
       "  {'result': 'PASS',\n",
       "   'name': 'MATCHES_PYRAMID',\n",
       "   'multiplier': 1.2,\n",
       "   'pyramids': [{'name': 'KOR/D1/Price Volume', 'multiplier': 1.2},\n",
       "    {'name': 'KOR/D1/Analyst', 'multiplier': 1.5}]}]}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "is_perf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
